package com.cqust.interceptor;


import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class PermissionInterceptor extends HandlerInterceptorAdapter {
    public boolean preHandle(HttpServletRequest request,
                             HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        //如果用户的角色是管理员，放行
        if (session.getAttribute("Role").equals("管理员")) return true;
        request.getRequestDispatcher("/WEB-INF/jsp/myInfo.jsp")
                .forward(request, response);
        return false;
    }
}
